package ch.tbz.M326.FileSearch;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Vector;

public class Files {
	
	private Vector<File> filesVector = null;
	private void search(){
		File[] drives = File.listRoots();
		for(int i = 0; i < drives.length; i++){
			File vic = drives[i];
			validateFile(vic);
		}
	}
	
	private void validateFile(File dir){
		File[] files = dir.listFiles();
		
		if (files != null) {
			for (int i = 0; i < files.length; i++) {
				if (files[i].isDirectory()) {
					validateFile(files[i]); 
				}else{
					if(files[i].getName().endsWith(".mp3")){
						setFile(files[i]);
					}
				}
			}
		}
	}
	
	public Vector<File> getFiles(){
		search();
		return filesVector;
	}
	
	private void setFile(File file){
		filesVector.add(file);
	}
}
